-- Shield impact effect for the Robotic Panels
-- All credit for inspiration and code goes to the Gmod Stargate team

EFFECT.Material = Material("refract_ring");

function EFFECT:Init(data)

  self.Size = 10
  self.StartSize = math.Clamp(data:GetScale()-self.Size,0,1337)
  self.Refract = 0
  
  local ent = data:GetEntity()
  if(!ent:IsValid()) then 
    return 
  end
  
  self.Parent = ent
  self.Normal = self.Parent:GetUp()
  self.Offset = data:GetOrigin()
  self.Pos = self.Parent:LocalToWorld(self.Offset)
  local offset = self.Size * Vector() * 200
  self.Entity:SetRenderBounds(-1 * offset, offset)
    
end


function EFFECT:Think()

  self.Normal = self.Parent:GetUp()
  self.Pos = self.Parent:LocalToWorld(self.Offset)
  self.Refract = self.Refract+FrameTime()
  self.Size = 20 * self.Refract^(0.2) + self.StartSize
  return (self.Refract < 1);
        
end 


function EFFECT:Render()

  if(self.Refract < 1 && ValidEntity(self.Parent)) then
    
    self.Material:SetMaterialFloat("$refractamount", math.sin(self.Refract * math.pi) * 0.1)
    render.SetMaterial(self.Material)
    render.UpdateRefractTexture()
    render.DrawQuadEasy(self.Pos + self.Normal * 3, self.Normal, self.Size, self.Size)
    render.DrawQuadEasy(self.Pos + self.Normal * 3, -1 * self.Normal, self.Size, self.Size)
          
  end
        
end